/**
 * 
 */
package dms.dto;

import java.text.ParseException;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

import dms.model.Dormitory;
import dms.model.form.ProcessStatus;
import dms.util.DateFormatUtil;

/**
 * @author 李健
 *
 */
public class PurchaseItemDTO extends ActionForm {
	private Long id;
	private Long dormitory;
	private String dormitoryName;
	private String contactTel;
	private String title;
	private String description;
	private String requestDate;
	private String fromDate;
	private String toDate;
	private Boolean processed;
	private Boolean applied;
	private String type;
	
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getFromDate() {
		return fromDate;
	}
	public void setFromDate(String fromDate) {
		this.fromDate = fromDate;
	}
	public String getToDate() {
		return toDate;
	}
	public void setToDate(String toDate) {
		this.toDate = toDate;
	}
	public Boolean getProcessed() {
		return processed;
	}
	public void setProcessed(Boolean processed) {
		this.processed = processed;
	}
	public Boolean getApplied() {
		return applied;
	}
	public void setApplied(Boolean applied) {
		this.applied = applied;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}
	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}
	/**
	 * @return the dormitory
	 */
	public Long getDormitory() {
		return dormitory;
	}
	/**
	 * @param dormitory the dormitory to set
	 */
	public void setDormitory(Long dormitory) {
		this.dormitory = dormitory;
	}
	/**
	 * @return the contactTel
	 */
	public String getContactTel() {
		return contactTel;
	}
	/**
	 * @param contactTel the contactTel to set
	 */
	public void setContactTel(String contactTel) {
		this.contactTel = contactTel;
	}
	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}
	/**
	 * @param description the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}
	/**
	 * @return the requestDate
	 */
	public String getRequestDate() {		
		return this.requestDate;
	}
	/**
	 * @param requestDate the requestDate to set
	 */
	public void setRequestDate(String requestDate) {
		this.requestDate = requestDate;
	}
	public String getDormitoryName() {
		return dormitoryName;
	}
	public void setDormitoryName(String dormitoryName) {
		this.dormitoryName = dormitoryName;
	}

	@Override
	public void reset(ActionMapping mapping, HttpServletRequest request) {
		this.applied = null;
		this.contactTel = null;
		this.description = null;
		this.dormitory = null;
		this.fromDate = null;
		this.id = null;
		this.processed = null;
		this.requestDate = null;
		this.toDate = null;
		this.type = null;
		this.title = null;
	}
	
	@Override
	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {
		ActionErrors errors = new ActionErrors();
		
		if (this.getTitle() == null || this.getTitle().length() == 0) {
			errors.add("title", new ActionMessage("缺少标题", false));
		}
		if (this.getDescription() == null || this.getTitle().length() == 0) {
			errors.add("description", new ActionMessage("缺少描述", false));
		}
		if (this.getContactTel() == null || this.getContactTel().length() == 0) {
			errors.add("contactTel", new ActionMessage("缺少联系电话", false));
		}
		
		if (!errors.isEmpty()) {
			request.setAttribute("status", true);
			request.setAttribute("message", errors.toString());
		}
		
		return errors;
	}
}
